package SortExe;

import java.util.Arrays;

public class BubbleSort {
    public static void bubbleSort(int[] arr,int l,int r){
        if (arr == null || r-l < 1){
            return;
        }
        for (int i = r; i > l ; i--) {
            boolean flg = false;
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j+1]){
                    swap(arr,j,j+1);
                    flg = true;
                }
            }
            if (flg == false){
                return;
            }
        }
    }
    public static void swap(int[] arr,int x,int y){
        int tmp = arr[x];
        arr[x] = arr[y];
        arr[y] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = {3,5,2,7,10,2,5,11};
        bubbleSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
}
